package com.btm.easymetadata.server.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.btm.easymetadata.server.entity.base.Response;
import com.btm.easymetadata.server.entity.dao.uniondao.PrdAllInfo;
import com.btm.easymetadata.server.entity.dto.PrdDTO;
import com.btm.easymetadata.server.entity.dto.PrdInfoDTO;
import com.btm.easymetadata.server.entity.vo.PrdAllInfoVO;
import com.btm.easymetadata.server.entity.vo.PrdInfoVO;
import com.btm.easymetadata.server.entity.vo.PrdVO;
import com.btm.easymetadata.server.entity.vo.PrdWithInfoVO;
import com.btm.easymetadata.server.service.PrdService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/prd")
@AllArgsConstructor
public class PRDController {

    private final PrdService prdService;

    @PostMapping("/add")
    public Response<Boolean> addPrd(@RequestBody PrdDTO prdDTO) {
        Response<Boolean> response = new Response<>();
        response.setCode(200);
        response.setData(prdService.addPrd(prdDTO));
        return response;
    }

    @PostMapping("/list")
    public Response<IPage<PrdVO>> listPrd(@RequestBody PrdDTO prdDTO) {
        Response<IPage<PrdVO>> response = new Response<>();
        response.setCode(200);
        response.setData(prdService.listPrd(prdDTO));
        return response;
    }

    @PostMapping("/info/add")
    public Response<Boolean> addPrdInfo(@RequestBody PrdInfoDTO prdInfoDTO) {
        Response<Boolean> response = new Response<>();
        response.setCode(200);
        response.setData(prdService.addPrdInfo(prdInfoDTO));
        return response;
    }

    @PostMapping("/info/list")
    public Response<IPage<PrdAllInfoVO>> listPrdInfo(@RequestBody PrdInfoDTO prdInfoDTO) {
        Response<IPage<PrdAllInfoVO>> response = new Response<>();
        response.setCode(200);
        response.setData(prdService.listPrdAllInfo(prdInfoDTO));
        return response;
    }

    /**
     * 查询单个PRD下的逻辑及使用到的数据字段
     */
    @GetMapping("/one")
    public Response<List<PrdWithInfoVO>> getPrdWhitInfo(@RequestParam("prdName") String prdName) {
        return null;
    }
}
